package com.biboheart.adapter.support.enums;

import com.biboheart.adapter.support.BaseEnum;
import com.biboheart.adapter.support.EnumValueObject;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public enum ValueTypeEnum implements BaseEnum<String, Class<?>> {
    VALUE_TYPE_STRING("string", String.class),
    VALUE_TYPE_LONG("long", Long.class),
    VALUE_TYPE_INT("int", Long.class),
    VALUE_TYPE_DOUBLE("double", Double.class),
    VALUE_TYPE_LIST("list", List.class),
    VALUE_TYPE_MAP("map", Map.class),
    ;
    private final String code;
    private final Class<?> type;

    ValueTypeEnum(String code, Class<?> type) {
        this.code = code;
        this.type = type;
    }

    @Override
    public String code() {
        return code;
    }

    @Override
    public Class<?> desc() {
        return type;
    }

    public static ValueTypeEnum getValueType(String code) {
        ValueTypeEnum[] valueTypeEnums = values();
        for (ValueTypeEnum valueTypeEnum : valueTypeEnums) {
            if (valueTypeEnum.code().equals(code)) {
                return valueTypeEnum;
            }
        }
        return null;
    }

    public static List<EnumValueObject<String, String>> list() {
        List<EnumValueObject<String, String>> list = new ArrayList<>();
        for (ValueTypeEnum valueTypeEnum : values()) {
            list.add(new EnumValueObject<>(valueTypeEnum.code(), valueTypeEnum.desc().getTypeName()));
        }
        return list;
    }
}
